package org.qydjk.h5.controller.index;

import org.qydjk.common.pojo.Article;
import org.qydjk.common.pojo.product.Product;
import org.qydjk.common.pojo.seller.Seller;
import org.qydjk.common.vo.PaginationInfo;
import org.qydjk.h5.controller.base.BaseController;
import org.qydjk.service.service.recommend.IRecommendService;
import org.qydjk.service.vo.ArticleList;
import org.qydjk.service.vo.ProductList;
import org.qydjk.service.vo.recommend.Banner;
import org.qydjk.service.vo.recommend.RecommendCategory;
import org.qydjk.service.vo.recommend.RecommendSeller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Deng_Junwei on 2018/1/4.
 */
@Controller
@RequestMapping("/index")
public class IndexController extends BaseController {
    @Autowired
    private IRecommendService recommendService;

    /**
     * 首页
     * @param model
     * @return
     */
    @RequestMapping("/index.do")
    public String index(Model model){
        try {
            //轮播图
            List<Banner> bannerList = recommendService.findBannerByLocId(getAreaId(),51, 5);
            model.addAttribute("bannerList",bannerList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "index/index";
    }

    /**
     * 平台
     *
     * @return
     */
    @RequestMapping("/platform.do")
    public String platform(Model model) {
        try {
            //轮播图
            List<Banner> bannerList = recommendService.findBannerByLocId(getAreaId(),52, 5);
            //分类
            List<RecommendCategory> recommendCategoryList = recommendService.findRecommendCategoryByLocId(getAreaId(),2, 4);
            //推荐商家
            List<RecommendSeller> recommendSellerList = recommendService.findRecommendSellerByLocId(getAreaId(),24, 8);

            model.addAttribute("bannerList",bannerList);
            model.addAttribute("recommendCategoryList",recommendCategoryList);
            model.addAttribute("recommendSellerList",recommendSellerList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "index/platform";
    }

    /**
     * 推荐产品
     * @param page
     * @return
     */
    @RequestMapping("/recommendProduct.do")
    @ResponseBody
    public Object recommendProduct(Integer page){
        try {

            Integer pageSize = 5;  //每页条数
            PaginationInfo recommendProductPagination = recommendService.findRecommendProductPagination(getAreaId(), 56, false,"15.2","133.2", page, pageSize);
            return renderListSuccess(recommendProductPagination.getList(),pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 推荐文章
     * @param page
     * @return
     */
    @RequestMapping("/recommendArticle.do")
    @ResponseBody
    public Object recommendArticle(Integer page){
        try {

            Integer pageSize = 5;  //每页条数
            PaginationInfo<ArticleList> recommendArticlePagination = recommendService.findRecommendArticlePagination(getAreaId(), 55, false, page, pageSize);
            return renderListSuccess(recommendArticlePagination.getList(),pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @RequestMapping("/richText.do")
    public String richText(Model model,Integer id){
        try {
            model.addAttribute("richText",recommendService.findContentById(id));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "richText";

    }

}
